package com.lvs.zmwz.util;

import cn.dev33.satoken.secure.SaSecureUtil;

/**
 * RSA非对称加密
 */
public class RsaUtil {

    // 定义私钥和公钥
   private final static String privateKey = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAIroaaR85BYtJgfGJgrzRhhmIBGaRnZW0npdICpx3olGBT38NTGRetG2OKg61+Bty8mQVBNAWFGUCrSmMca+b9yGNf93D3QgpjqdmXF7X55Adp1ScwQiIcmUrMizzEarzs2GwC+bvf4qe6TO1CCL8q4OwYrEON9Tx2//Cwj25AXZAgMBAAECgYEAiDl6+Pwd9v2Z8T/KqSyAzobA5mJkvcNRsPzJAbcgJYGMvIgtZookZ6uLjrf+Y7NpiifHvAV7V62WfikKYbz7F1ato7YBnsvdFoKOnW1MkIEap3M5ocF0t70ZpNFKc+er8IAAxUYe7UZOkkmBr69kRCCE/hT9f867cnsrj4YaEY0CQQDQhpzTx94Qu3Is7ffyRBXiWzwlkcdRyeVeNapwcEJLO4tKDKNIha2uq5IcSkBQ0qfXeoR+fkP8FgwgbvhreIRnAkEAqohMGUI81IBM5IbYjbdQV5gJm0m6KKK0tOaAvg0DzJguY67nF9m+yJ2+Z/FLEPa8rh8pssz+ZvSNiOBhbW67vwJAdGMd92qv/IDTClbMNHFiEZRArut9552bowirF9Tge6NBbFQ/csQCG+LxS076NOJPAgsFFqEdCv+3RwcJKtr6cwJBAIFtaLRS/XAa4EEhxwHn+2Y/0iq1zkBBHP2fZF7Z6eRCLBMkD+ieLpp8fqLNE7gQTCurIy69PuhM+47DHa68uGkCQQCDZnLE0QTVsjQ7f/dzPFQNkf7Dztnd4gJGym2nbSudU7KeDt6tQZngWAwx9nGg0g4oYafIv6TW1gAwPO8OUs/m";
   private final static String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCK6GmkfOQWLSYHxiYK80YYZiARmkZ2VtJ6XSAqcd6JRgU9/DUxkXrRtjioOtfgbcvJkFQTQFhRlAq0pjHGvm/chjX/dw90IKY6nZlxe1+eQHadUnMEIiHJlKzIs8xGq87NhsAvm73+KnukztQgi/KuDsGKxDjfU8dv/wsI9uQF2QIDAQAB";


    public static void main(String[] args) throws Exception {
        // 生成一对公钥和私钥，其中Map对象 (private=私钥, public=公钥)
        //System.out.println(SaSecureUtil.rsaGenerateKeyPair());
        // 文本
        String text = "admin";
        // 使用公钥加密
        String ciphertext = SaSecureUtil.rsaEncryptByPublic(publicKey, text);
        System.out.println("公钥加密后：" + ciphertext);
        // 使用私钥解密
        String text2 = SaSecureUtil.rsaDecryptByPrivate(privateKey, ciphertext);
        System.out.println("私钥解密后：" + text2);
    }

    /**
     * 加密
     * @return
     */
    public static String setRsaPwd(String pwd){
        // 使用公钥加密
        return SaSecureUtil.rsaEncryptByPublic(publicKey, pwd);
    }

    /**
     * 解密
     * @return
     */
    public static String getRsaPwd(String pwd){
        // 使用私钥解密
        return SaSecureUtil.rsaDecryptByPrivate(privateKey, pwd);
    }

}
